package Controler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTextField;

import Data.Name;

public class InformationsListener implements MouseListener, KeyListener {
	private Controler controler;
	private JTextField editable;
	
	public InformationsListener(Controler controler){
		this.controler = controler;
		editable = null;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if(e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1){
			editable = (JTextField)e.getSource();
			editable.setEditable(true);
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {

	}

	@Override
	public void mouseExited(MouseEvent arg0) {

	}

	@Override
	public void mousePressed(MouseEvent arg0) {

	}

	@Override
	public void mouseReleased(MouseEvent arg0) {

	}

	@Override
	public void keyPressed(KeyEvent arg0) {
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		if(e.getKeyCode() == e.VK_ENTER && editable != null && editable.isEditable()){
			editable.setEditable(false);
			Name n = new Name(Integer.parseInt(editable.getName()),editable.getText());
			controler.send(n);
		}
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		
	}

}
